Skip to content

fix(snapchat): proxy bundled config loads - #823

Merged
harlan-zw merged 3 commits into
mainfrom
fix/snapchat-bundle-config-proxy
Jul 14, 2026
Merged

fix(snapchat): proxy bundled config loads#823
harlan-zw merged 3 commits into
mainfrom
fix/snapchat-bundle-config-proxy

Conversation

@harlan-zw

@harlan-zw harlan-zw commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

🔗 Linked issue

Resolves #822

❓ Type of change

  • 📖 Documentation
  • 🐞 Bug fix
  • 👌 Enhancement
  • ✨ New feature
  • 🧹 Chore
  • ⚠️ Breaking change

📚 Description

Bundled scevent.min.js was deriving its config host from the local asset URL, then loading /config/... from the app origin. This adds scoped SDK patches for new URL(...).host and script-loader URL arguments so Snapchat config loads go through the tr.snapchat.com proxy without depending on current minified names.

The Snapchat first-party e2e now forces a fresh upstream bundle and fails if /config/... is requested from the app origin. The bundled SDK regression test also derives Snapchat proxy settings from the registry so domains and patches cannot drift silently.

@vercel

vercel Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
scripts-playground Ready Ready Preview, Comment Jul 14, 2026 3:40am

@pkg-pr-new

pkg-pr-new Bot commented Jul 4, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/scripts@823

commit: 26a2713

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2c015321-5d90-48ef-907f-33a3b465d606

📥 Commits

Reviewing files that changed from the base of the PR and between f27c4b4 and 26a2713.

📒 Files selected for processing (9)
  • packages/script/src/plugins/rewrite-ast.ts
  • packages/script/src/registry.ts
  • packages/script/src/runtime/types.ts
  • test/e2e-dev/first-party.test.ts
  • test/fixtures/first-party/nuxt.config.ts
  • test/fixtures/first-party/pages/snap.vue
  • test/unit/bundle-sdk-patches.test.ts
  • test/unit/rewrite-ast.test.ts
  • test/unit/transform.test.ts
🚧 Files skipped from review as they are similar to previous changes (7)
  • test/fixtures/first-party/nuxt.config.ts
  • test/unit/bundle-sdk-patches.test.ts
  • test/unit/transform.test.ts
  • test/fixtures/first-party/pages/snap.vue
  • packages/script/src/runtime/types.ts
  • test/e2e-dev/first-party.test.ts
  • packages/script/src/plugins/rewrite-ast.ts

📝 Walkthrough

Walkthrough

Adds typed SDK patches and AST passes that pin Snapchat host detection and rewrite script-loader config URLs through the Nuxt proxy. Snapchat registry bundle and proxy configurations now use these patches. Unit, integration, and e2e tests cover rewriting, forced bundling, cache paths, same-origin requests, and fixture behavior.

Estimated code review effort: 4 (Complex) | ~45 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.53% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title concisely describes the main change: fixing Snapchat bundled config loading via proxying.
Description check ✅ Passed The description matches the implemented Snapchat bundle/proxy patching and test updates.
Linked Issues check ✅ Passed The PR adds SDK patches and registry proxy handling so bundled Snapchat config loads through the intended proxy path, matching #822.
Out of Scope Changes check ✅ Passed The changes stay focused on Snapchat bundling, proxy rewrites, and related tests without unrelated scope.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/snapchat-bundle-config-proxy

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (3)
test/unit/bundle-sdk-patches.test.ts (1)

151-182: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Hardcoded snapchatPixel config duplicates registry.ts; risks drift.

This inline proxyConfigs.snapchatPixel mirrors the actual registry entry (packages/script/src/registry.ts) but isn't sourced from it, unlike the analogous suite in test/unit/rewrite-ast.test.ts which calls getProxyConfigs(). If the registry's sdkPatches/domains for snapchatPixel change, this test will keep passing against a stale snapshot instead of failing.

♻️ Suggested refactor: derive from registry
-        proxyConfigs: {
-          snapchatPixel: {
-            domains: ['sc-static.net', 'tr.snapchat.com', 'pixel.tapad.com'],
-            sdkPatches: [
-              { type: 'replace-new-url-host', host: 'sc-static.net' },
-              { type: 'replace-script-loader-url', fromDomain: 'tr.snapchat.com', pathPrefix: '/config' },
-            ],
-          } as any,
-        },
+        proxyConfigs: {
+          snapchatPixel: (await buildProxyConfigsFromRegistry(await registry())).snapchatPixel as any,
+        },
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/unit/bundle-sdk-patches.test.ts` around lines 151 - 182, The Snapchat
proxy test is hardcoding a stale `proxyConfigs.snapchatPixel` snapshot instead
of using the shared registry data. Update the `applies snapchat config host
patches to bundled proxy scripts` test to derive `proxyConfigs` from the
registry source used elsewhere (for example via the same helper pattern as
`rewrite-ast.test.ts` and `getProxyConfigs()`), so `sdkPatches` and `domains`
stay aligned with `registry.ts` and future registry changes are caught.
test/unit/transform.test.ts (1)

645-687: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Drop the hash mock or assert the cache key. vi.mocked(hash).mockImplementationOnce(() => 'scevent.min') only affects the intermediate source filename/cache key; the emitted asset URL still comes from the fetched content hash. If this test isn’t checking cache naming, the mock is unnecessary.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/unit/transform.test.ts` around lines 645 - 687, The `transform` test for
`useScriptSnapchatPixel` is over-mocking `hash` in a way that only affects the
intermediate cache key, not the emitted asset URL. Remove the
`vi.mocked(hash).mockImplementationOnce(...)` stub unless the test explicitly
asserts cache-key behavior, or update the expectations to verify the cache key
produced by the `bundle` path and its interaction with `mockBundleStorage`. Keep
the assertions focused on the actual `transform` output and the fetch bypass
behavior.
test/fixtures/first-party/nuxt.config.ts (1)

4-5: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Grammatically broken comment.

"Pages that need the real SDK load provide an explicit trigger" doesn't parse. Likely meant "Pages that need the real SDK should provide an explicit trigger...".

✏️ Suggested wording fix
 // trigger: 'manual' prevents the auto-generated plugin from loading all 18
-// scripts globally on every page. Pages that need the real SDK load provide an
-// explicit trigger in their composable call, keeping cross-provider noise low.
+// scripts globally on every page. Pages that need the real SDK should provide
+// an explicit trigger in their composable call, keeping cross-provider noise low.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/fixtures/first-party/nuxt.config.ts` around lines 4 - 5, The inline
comment in the Nuxt config is grammatically broken and should be rewritten for
clarity. Update the descriptive text near the existing explanatory comment so
that the sentence about pages needing the real SDK reads naturally, using the
same surrounding context in the configuration block. Keep the meaning intact
while fixing the wording in the comment text itself.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@test/fixtures/first-party/nuxt.config.ts`:
- Around line 4-5: The inline comment in the Nuxt config is grammatically broken
and should be rewritten for clarity. Update the descriptive text near the
existing explanatory comment so that the sentence about pages needing the real
SDK reads naturally, using the same surrounding context in the configuration
block. Keep the meaning intact while fixing the wording in the comment text
itself.

In `@test/unit/bundle-sdk-patches.test.ts`:
- Around line 151-182: The Snapchat proxy test is hardcoding a stale
`proxyConfigs.snapchatPixel` snapshot instead of using the shared registry data.
Update the `applies snapchat config host patches to bundled proxy scripts` test
to derive `proxyConfigs` from the registry source used elsewhere (for example
via the same helper pattern as `rewrite-ast.test.ts` and `getProxyConfigs()`),
so `sdkPatches` and `domains` stay aligned with `registry.ts` and future
registry changes are caught.

In `@test/unit/transform.test.ts`:
- Around line 645-687: The `transform` test for `useScriptSnapchatPixel` is
over-mocking `hash` in a way that only affects the intermediate cache key, not
the emitted asset URL. Remove the `vi.mocked(hash).mockImplementationOnce(...)`
stub unless the test explicitly asserts cache-key behavior, or update the
expectations to verify the cache key produced by the `bundle` path and its
interaction with `mockBundleStorage`. Keep the assertions focused on the actual
`transform` output and the fetch bypass behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bd56888e-76f0-4664-a05b-f77b2325e04d

📥 Commits

Reviewing files that changed from the base of the PR and between 385b058 and dfd7a13.

📒 Files selected for processing (9)
  • packages/script/src/plugins/rewrite-ast.ts
  • packages/script/src/registry.ts
  • packages/script/src/runtime/types.ts
  • test/e2e-dev/first-party.test.ts
  • test/fixtures/first-party/nuxt.config.ts
  • test/fixtures/first-party/pages/snap.vue
  • test/unit/bundle-sdk-patches.test.ts
  • test/unit/rewrite-ast.test.ts
  • test/unit/transform.test.ts

@harlan-zw harlan-zw changed the title fix: proxy Snapchat bundled config loads fix(snapchat): proxy bundled config loads Jul 14, 2026
…ed subtrees

Rewriting a loader argument then descending into it could produce
conflicting MagicString edits when the argument contained a literal the
domain-rewrite pass also matched. Skip the replaced subtree instead.

Match each replace-script-loader-url patch against its own pathPrefix so
multiple patches can't rewrite a path to the wrong proxied domain.
@harlan-zw
harlan-zw force-pushed the fix/snapchat-bundle-config-proxy branch from b756a68 to 26a2713 Compare July 14, 2026 03:38
@harlan-zw
harlan-zw merged commit 5167283 into main Jul 14, 2026
19 checks passed
@harlan-zw
harlan-zw deleted the fix/snapchat-bundle-config-proxy branch July 14, 2026 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bundling the Snapchat pixel breaks it: scevent.min.js resolves its config URL against the page origin

1 participant